<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>类别管理</title>
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="css/admin.css"/>
</head>
<body >
<!--侧边栏-->
<aside class="ad_aside">
    <!--商标-->
    <div class="brand"><a href="index.html">Mall</a></div>
    <!--用户-->
    <div class="user">
        <img src="images/default.png" alt=""/>
        <span>超级管理员</span>
    </div>
    <!--菜单-->
    <div class="menu">
        <ul>
            <li><a href="user.html"><span class="glyphicon glyphicon-user"></span> 用户管理</a></li>
            <li class="now">
                <a href="javascript:;"><span class="glyphicon glyphicon-list"></span> 分类管理</a>
                <div class="child">
                    <a class="now" href="category.html">一级分类</a>
                    <a href="brand.html">二级分类</a>
                </div>
            </li>
            <li><a href="product.html"><span class="glyphicon glyphicon-tags"></span> 商品管理</a></li>
        </ul>
    </div>
</aside>
<!--内容-->
<section class="ad_section">
    <!--顶部导航-->
    <nav class="ad_nav">
        <a data-menu href="javascript:;"><span class="glyphicon glyphicon-align-justify"></span></a>
        <a data-logout href="javascript:;"><span class="glyphicon glyphicon-log-out"></span></a>
    </nav>
    <div class="container-fluid">
        <!--路径导航-->
        <ol class="breadcrumb">
            <li><a href="#">管理系统</a></li>
            <li class="active">分类管理</li>
            <li class="active">一级分类</li>
        </ol>
        <div id="app">
            <div class="ad_content" >
                <button id="addBtn" class="btn btn-default mb_15">添加分类</button>
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th width="20%">序号</th>
                        <th width="80%">分类名称</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item,i) in list">
                        <td>{{i+1}}</td>
                        <td>{{item.categoryName}}</td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="modal fade" id="addModal">
                <div class="modal-dialog modal-sm">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span>&times;</span></button>
                            <h4 class="modal-title">添加分类</h4>
                        </div>
                        <div class="modal-body">
                            <form action="#" id="form">
                                <div class="form-group">
                                    <input v-model="categoryName" name="categoryName" type="text" class="form-control" placeholder="请输入一级分类名称">
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" form="form" @click="click1">确定</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>


<script src="assets/jquery/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="js/vue-2.6.12.js"></script>
<script src="js/axios-0.21.0.js"></script>
<script src="js/qs-6.9.4.js"></script>
<script>
    new Vue({
        el:'#app',
        data:{
            list:null,
            categoryName:""
        },
        mounted(){
            axios.get('http://127.0.0.1:8000/api/categorys')
                .then(resp => this.list = resp.data.categorylist)
        },
        methods:{
            click1:function (){
               axios.post('http://127.0.0.1:8000/api/addcategory',Qs.stringify({
                   categoryName: this.categoryName
               })).then(resp => {
                    $('#addModal').modal('hide');
                    this.list = resp.data.categorylist
               })
            }
        }
    })

    $('#addBtn').on('click',function () {
        /*显示模态框*/
        $('#addModal').modal('show');
    });
</script>
</body>
</html>